Skip to content

fix : prevent reflected XSS by encoding var_export() output#623

Merged
rowan-m merged 1 commit into
google:mainfrom
g0w6y:fix/xss-htmlspecialchars-examples
Apr 27, 2026
Merged

fix : prevent reflected XSS by encoding var_export() output#623
rowan-m merged 1 commit into
google:mainfrom
g0w6y:fix/xss-htmlspecialchars-examples

Conversation

@g0w6y
Copy link
Copy Markdown
Contributor

@g0w6y g0w6y commented Apr 5, 2026

All 6 example files reflect unsanitized POST data and response objects
directly into HTML via var_export() with no encoding, allowing reflected
XSS via the g-recaptcha-response parameter.

PoC :

curl -X POST https://recaptcha-demo.appspot.com/recaptcha-v2-checkbox.php \
  --data-urlencode 'g-recaptcha-response=</pre><img src=x onerror=alert(document.domain)>'

Root cause:
var_export($_POST) and var_export($resp) write user-controlled data into
HTML with zero encoding. No htmlspecialchars() exists anywhere in examples/.
The </pre> in the payload breaks out of the tag and the browser executes
the injected script.

Fix:
Replaced all var_export() calls with:
htmlspecialchars(print_r(..., true), ENT_QUOTES | ENT_HTML5, 'UTF-8')
across 6 files, 18 lines total. No logic changes.

Files changed:

  • examples/recaptcha-v2-checkbox.php
  • examples/recaptcha-v2-checkbox-explicit.php
  • examples/recaptcha-v2-invisible.php
  • examples/recaptcha-request-curl.php
  • examples/recaptcha-request-post.php
  • examples/recaptcha-request-socket.php

These files are actively deployed on recaptcha-demo.appspot.com and widely
copied by developers into production insecure patterns here propagate
directly into real applications.

@rowan-m
Copy link
Copy Markdown
Contributor

rowan-m commented Apr 10, 2026

I don't have tests that run the demos (yet... I suppose I really should set up an e2e suite) so l will need to test this locally before merging.

@g0w6y
Copy link
Copy Markdown
Contributor Author

g0w6y commented Apr 27, 2026

Any Updates

@rowan-m
Copy link
Copy Markdown
Contributor

rowan-m commented Apr 27, 2026

Tested demos and they're working. Thanks!

@rowan-m rowan-m merged commit f760d88 into google:main Apr 27, 2026
1 check passed
@g0w6y
Copy link
Copy Markdown
Contributor Author

g0w6y commented Apr 27, 2026

Hey I would like to know for this issue any cve will be assigned ? @rowan-m

@rowan-m
Copy link
Copy Markdown
Contributor

rowan-m commented Apr 27, 2026

Hey I would like to know for this issue any cve will be assigned ? @rowan-m

The issue was in the demo code, so there's not really anything user-facing or affecting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants